package com.mentaleye.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.UserLoginDao;
import com.mentaleye.dal.model.UserLogin;
import com.mentaleye.dal.model.UserLoginExample;
import com.mentaleye.dal.model.UserLoginExample.Criteria;
import com.mentaleye.service.UserLoginService;

@Service
public class UserLoginServiceImpl implements UserLoginService {

	@Autowired private UserLoginDao dataDao;
	
	@Override
	public boolean insertRecord(UserLogin data) {
		return this.dataDao.insertRecord(data);
	}
	
	@Override
	public boolean insertByList(List<UserLogin> dataList) {
		return this.dataDao.insertByList(dataList);
	}

	@Override
	public boolean updateRecord(UserLogin data) {
		return this.dataDao.updateRecord(data);
	}
	
	@Override
	public boolean updateRecordBySelective(UserLogin data) {
		return this.dataDao.updateRecordBySelective(data);
	}
	
	@Override
	public UserLogin getBySelective(String loginName, int userType) {
		UserLogin data=null;
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginNameEqualTo(loginName);
		criteria.andUserTypeEqualTo(userType);
		List<UserLogin> dataList = this.dataDao.getListByExample(example);
		if(!dataList.isEmpty()){
			data=dataList.get(0);
		}
		return data;
	}

	@Override
	public UserLogin getBySelective(String loginName, String password) {
		UserLogin data=null;
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginNameEqualTo(loginName);
		criteria.andPasswordEqualTo(password);
		List<UserLogin> dataList = this.dataDao.getListByExample(example);
		if(!dataList.isEmpty()){
			data=dataList.get(0);
		}
		return data;
	}
	
	@Override
	public UserLogin getBySelective(String loginName, String password, int userType) {
		UserLogin data=null;
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginNameEqualTo(loginName);
		criteria.andPasswordEqualTo(password);
		criteria.andUserTypeEqualTo(userType);
		List<UserLogin> dataList = this.dataDao.getListByExample(example);
		if(!dataList.isEmpty()){
			data=dataList.get(0);
		}
		return data;
	}
	
	@Override
	public List<UserLogin> getListByLoginName(String loginName) {
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginNameEqualTo(loginName);
		return this.dataDao.getListByExample(example);
	}
	
	@Override
	public boolean deleteByKeyList(List<Integer> keyList) {
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdIn(keyList);
		return this.dataDao.deleteByExample(example);
	}

	@Override
	public boolean deleteByLoginIdList(List<String> loginIdList) {
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginIdIn(loginIdList);
		return this.dataDao.deleteByExample(example);
	}
	
	@Override
	public boolean deleteBySelective(List<String> loginIdList, int userType) {
		UserLoginExample example=new UserLoginExample();
		Criteria criteria = example.createCriteria();
		criteria.andLoginIdIn(loginIdList);
		criteria.andUserTypeEqualTo(userType);
		return this.dataDao.deleteByExample(example);
	}

	@Override
	public List<Map<String, Object>> getLoginByMap(Map<String, Object> map) {
		return this.dataDao.getLoginByMap(map);
	}
}
